import os
import os.path
import subprocess
from django.core.management import base

def startdaemon():
    from django.conf import settings

    if settings.DAEMON_NO_BACKGROUND:
        from streamux.daemon.main import main
        main()
    elif os.path.exists(settings.DAEMON_PIDFILE):
        print 'PID file exists, not starting'
    else:
        os.system(settings.SITE_ROOT + '/daemon/main.py')

class Command(base.BaseCommand):
    can_import_settings = True
    help = 'Start the music processing daemon'

    def handle(self, *args, **kwargs):
        startdaemon()
